<script type="text/javascript">
var supplierMap = [];
{foreach from=$supplierMap key=supplierId item=modelData}
supplierMap[{$supplierId}] = [];
{foreach from=$modelData item=model}
supplierMap[{$supplierId}].push(OPTION({literal}{{/literal}'value': {$model.id}{literal}}{/literal}, "{$model.name}"));
{/foreach}
{/foreach}
</script>

{$form.javascript}
<form {$form.attributes}>
<table width="100%" border="0" cellspacing="0" cellpadding="4" class="form" id="searchFormHeader">
  <thead>
    <tr>
      <td colspan="3">{t}Search criteria{/t}</td>
      <td>
      <input id="searchform_switch" title="{t}Show/Hide{/t}"
        value="{if $DisplayForm != 'none'}-{else}+{/if}" type="button"
        onclick="fw.dom.toggleElement('searchform_fields', null, 'searchform_switch');" />
	  </td>
    </tr>
  </thead>
  <tfoot class="css_disabled"><tr><td colspan="4"/></tr></tfoot>
  <tbody class="css_disabled"><tr><td colspan="4"/></tr></tbody>
</table>
<div id="searchform_fields" class="generic_form" style="display:{$DisplayForm|default:block}">
<table width="100%" border="0" cellspacing="0" cellpadding="4" id="searchForm">
  <tfoot>
    <tr>
      <td colspan="4" align="right">
      <input type="hidden" name="formSubmitted" value="1" />
	  <input type="submit" value="{t}OK{/t}" name="OK" class="Button"
        onclick="return checkForm($('SupplyingOptimization'), requiredFields);" />
	  </td>
    </tr>
  </tfoot>
  <tbody>
    <tr class="search">
	  <td class="element_label">{$form.Supplier.label}:</td>
      <td class="element_html">{$form.Supplier.html}{$form.hidden}</td>
      {if $form.Model} 
      <td class="element_label">{$form.Model.label}</td>
      <td class="element_html">{$form.Model.html}</td>
      {else}
      <td class="element_label">&nbsp;</td>
      <td class="element_html">&nbsp;</td>
      {/if}
    </tr>
    <tr class="search">
	  <td nowrap="nowrap">{$form.PassedWeekNumber.label}:</td>
      <td>{$form.PassedWeekNumber.html}</td>
	  <td nowrap="nowrap">{$form.FutureWeekNumber.label}:</td>
      <td>{$form.FutureWeekNumber.html}</td>
    </tr>
    <tr class="search">
	  <td nowrap="nowrap">{$form.DefaultDeliveryDelay.label}:</td>
      <td>{$form.DefaultDeliveryDelay.html}</td>
	  <td nowrap="nowrap">{$form.WithExtrapolation.label}:</td>
      <td>{$form.WithExtrapolation.html}</td>
    </tr>
  </tbody>
</table>
</div>
</form>
<div id="weeks" class="generic_form" style="display:{$DisplayResult|default:none}">
<table width="100%" border="0" cellspacing="0" cellpadding="4" id="weeksTable">
  <thead>
    <tr>
      <td>&nbsp;</td>
	  {section name=weekIndex loop=$wishedStartDateArray}
	  <td>{t}Week{/t} {$smarty.section.weekIndex.index}</td>
      {/section}
    </tr>
  </thead>
  <tbody>
    <tr class="search">
	  <td>{t}Supplying dates{/t}</td>
	  {section name=week loop=$wishedStartDateArray}
	  <td>{$wishedStartDateArray[week]}</td>
      {/section}
    </tr>
</table>
</div>
{if $DisplayResult eq 'block'}
<br />
<div id="results" class="grid">
<table width="100%" border="0" cellspacing="0" cellpadding="4" id="resultsTable" class="grid">
  <thead>
    <tr>
      <td colspan="{math equation="x + 4" x=$futureWeekNumber}">
        {t}Expected consumption and suggested supplying quantities for supplier{/t} {$supplierName}
      </td>
    </tr>
    <tr>
	  <td>{t}Reference{/t}</td>
	  {section name=weekI loop=$wishedStartDateArray}
	  <td>{t}Week{/t} {$smarty.section.weekI.index}</td>
      {/section}
      <td>{t}Stock{/t}</td>
      <td>{t}Virtual qty{/t}</td>
      <td>{t}Minimum qty{/t}</td>
    </tr>
  </thead>
  <tbody>
    {foreach key=key item=item from=$productInfoList}
    <tr>
	  <td>{$item.BaseReference} {if $substitutionInfoList[$key] neq ''}*{/if}</td><!-- {$key} contient le pdtId -->
	  <td colspan="{$futureWeekNumber}">{$item.Name} {$substitutionInfoList[$key]}</td>
      <td>{$item.QR}</td>
      <td>{$item.QV}</td>
      <td>{$item.MiniStoredQty}</td>
    </tr>
    <tr class="grid_row_odd" style="border-bottom: 1px solid #000;">
	  <td>{t}Quantities{/t}</td>
	  {section name=weekNb loop=$wishedStartDateArray}
      <td>
          {$orderedQtyPerWeek[$key][weekNb]} 
          {if $orderedQtyPerWeekInEstimate[$key][weekNb]} 
          <span style="color: green">({$orderedQtyPerWeekInEstimate[$key][weekNb]})</span>
          {/if}
        | {$waitedQtyPerWeek[$key][weekNb]}
        | {if $qtyToOrder[$key][weekNb] > 0}<strong>{/if}
          {$qtyToOrder[$key][weekNb]}{if $qtyToOrder[$key][weekNb] > 0}</strong>{/if}
      </td>
      {/section}
      <td colspan="3">&nbsp;</td>
    </tr>
    {/foreach}
</table>

<br />
<form id="sumNeedsForm" name="sumNeedsForm" method="post" action="SupplyingOptimization.php">
<table width="100%" border="0" cellspacing="0" cellpadding="4" id="searchForm">
  <tfoot>
    <tr>
      <td colspan="2" align="right">
      <input type="hidden" name="formSubmitted" value="2" />
      <input type="hidden" name="Supplier" value="{$supplierId}" />
	  <input type="submit" value="{t}Sum needs{/t}" name="OK" class="Button"
        onclick="return checkDate();" />
	  </td>
    </tr>
  </tfoot>
  <tbody>
    <tr class="search">
	  <td class="element_label">{t}Please select a date to view suggested quantities at this date{/t}:</td>
      <td class="element_html"><span id="show_Date1"
				style="background-color:#E1E8EF;border:1px #000000 dotted;
				margin: 3px 3px 3px 3px;padding: 3px 3px 3px 3px;text-align: right;">
				{if $wishedStartDate!=0}{$wishedStartDate}{else}-- {t}Select a date{/t} --{/if}
				</span>
                <input type="hidden" name="StartDate" id="f_date_c1" value="{$wishedStartDate}" />
                &nbsp;<input type="button" name="f_trigger_c1" id="f_trigger_c1" value="..."
                style="cursor: pointer;" title="{t}Select a date{/t}" /></td>
    </tr>
  </tbody>
</table>
</form>
{literal}
            <script type="text/javascript">
//<![CDATA[
			Calendar.setup({
		        inputField     :    "f_date_c1",         // id of the input field (hidden)
		        ifFormat       :    "%Y-%m-%d",  // format of the input field
				displayArea    :    "show_Date1",         // ID of the span where the date is to be shown
				daFormat       :    "%A %e %B %Y",  // format of the displayed date
		        button         :    "f_trigger_c1",       // trigger for the calendar (button ID)
		        align          :    "Tl",                 // alignment (defaults to "Bl")
				date		   :	"", // date affichee par defaut
		        singleClick    :    true,
		        showsTime      :    false,
				dateStatusFunc :	dateStatusHandler     // permet d'afficher des dates speciales diffaremment (jours feries)
														  // et d'en desactiver (en fonction du planning de l'Actor
		    });
//]]>
			</script>
            {/literal}
</div>
{/if}
